from certificate_manager.models import *
from certificate_manager.serializers import DepartmentSerializer, UserSerializer, CertSerializer
from django.test import tag
from rest_framework import status
from rest_framework.renderers import JSONRenderer
from rest_framework.test import APITestCase
from .cate import CateTestCase

class CollectCateTests(APITestCase):

	def setUp(self):
		dep = Department.objects.create(name='test dep')
		dep.save()
		
		User.objects.create_superuser(uid='1', name='yves', password='123', department=dep)

	def test_add_ccate(self):
		CateTestCase.add_cates([('测试', None)])
		url = '/collectcates/'
		data = {
			'cate': 1
		}
		self.client.login(uid='1', password='123')
		response = self.client.post(url, data, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

	def test_get_ccate_list(self):
		# 获取要收集的ccate信息
		# 先创建一些Cate，然后才能收集
		CateTestCase.add_cates([('一级竞赛', None), ('蓝桥杯', 1)])
		# 创建CollectCate
		CollectCate.objects.create(cate=Cate.objects.get(name='蓝桥杯')).save() # 这里也需要控制，不是所有的类别都能添加ccate

		url = '/collectcates/'
		data = {}
		response = self.client.get(url, data, format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)
		self.assertEqual(len(response.data), 1)
